
#include<bits/stdc++.h>
using namespace std;

const int N = 101000;
const int M = 101000;
int p[M],c[M];
double d[N],v[N],a[N];
int n,m,L,V,T;
int sumcar=0,sumsp=0,ans=0;

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);

    cin>>T;
    while(T--){
        memset(c,0,sizeof(c));
        cin>>n>>m>>L>>V;
        for(int i=0;i<n;i++)cin>>d[i]>>v[i]>>a[i];
        for(int i=0;i<m;i++)cin>>p[i];
        //in

        for(int i=0;i<n;i++){
            if(a[i]==0){
                if(v[i]>V && d[i]<=p[m-1])sumcar++;
            }

            else if(a[i]<0){
                double s=0;
                for(int j=0;j<m;j++)
                    if(p[j]>d[i]){
                        s=p[j]-d[i];
                        break;
                    }
                if(sqrt(v[i]*v[i]+2*a[i]*s)>V)sumcar++;
            }

            else{
                double s=0;
                s=d[i]+(V*V-v[i]*v[i])/(2*a[i]);
                if(s<p[m-1])sumcar++;
            }
        }//all sumcar right

        for(int i=0;i<n;i++){
            if(a[i] == 0){
                if(v[i]>V)c[m-1]=1;
            }//a=0

            else if(a[i] < 0){
                int j=0;
                while(d[i]>p[j]){
                    j++;
                }
                int next=p[j];
                if((sqrt(v[i]*v[i]+2*a[i]*(next-d[i]))) > V){
                    //sumcar++;
                    c[j]=1;
                }
            }//a<0

            else{
                if(v[i] > V){
                    sumcar++;
                    for(int j=0;j<m;j++){
                        if(p[j]>=d[i]){
                            c[j]=1;
                            break;
                        }
                    }
                }
                else{
                    d[i]+=(V*V-v[i]*v[i])/(2*a[i]);
                    for(int j=0;j<m;j++){
                        if(p[j]>=d[i]){
                            c[j]=1;
                            break;
                        }
                    }
                }
            }//a>0
        }
        for(int i=0;i<m;i++)if(c[i]==1)ans++;
        cout<<sumcar<<" "<<m-ans<<endl;
        sumcar=0,ans=0;
    }

    return 0;
}

